package com.yibao.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.yibao.model.User;
import com.yibao.mapper.UserMapper;
import com.yibao.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: atguigu
 * @create: 2024-06-25 14:58
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    /**
     * 保存用户信息
     *
     * @param user
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveUser(User user) {
        String pwd = SecureUtil.md5(user.getPassword());
        user.setPassword(pwd);
        this.save(user);
    }

    @Override
    @Cacheable(value = "user", key = "#id")
    public User getUserInfo(Long id) {
        return this.getById(id);
    }
}
